package main.java.com.chegg.coursepicker;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

/**
 *
 *
 *
 */
public class JobSummary extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        processRequest(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        processRequest(req, resp);
    }

    private void processRequest(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        PrintWriter out = response.getWriter();

        String _userId = request.getParameter("userId");
        String _courseId = request.getParameter("courseId");

        int userId = Integer.parseInt(_userId);
        int courseId = Integer.parseInt(_courseId);

        IndeedSearch indeedSearch = new IndeedSearch();
        ArrayList<JobDescTO> arrayList = indeedSearch.searchIndeed(courseId, userId);

        RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/results.jsp");
        request.setAttribute("jobDescTO",arrayList);
        dispatcher.forward(request, response);

        out.close();
    }
}
